﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RkLibs.Security
{
    public partial class FrmRegister : Form
    {
        SoftwareRegister softReg;
        public FrmRegister(SoftwareRegister softwareRegister)
        {
            InitializeComponent();
            softReg = softwareRegister;
            this.tbHostIdentify.Text = softReg.HostIdentify;
            this.tbSoftName.Text = softReg.SoftwareName;
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            softReg.RegisterSoftware(this.tbUserID.Text, this.rtbRegStr.Text);
            if (softReg.RegResult == RegisterResult.SUCCEED)
            {
                MessageBox.Show("注册成功，谢谢使用","提醒");
                CloseForm();
            }
            else
            {
                MessageBox.Show("注册失败，请重新输入注册码", "提醒");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MenuItemCopy_Click(object sender, EventArgs e)
        {
            try
            {
                Clipboard.Clear();
                Clipboard.SetText(this.rtbRegStr.Text);
            }
            catch
            {

            }
        }

        private void MenuItemPaste_Click(object sender, EventArgs e)
        {
            try 
            {
                this.rtbRegStr.Text = Clipboard.GetText();
            }
            catch
            {

            }
        }
        private delegate void dg_CloseForm();
        private void CloseForm()
        {
            if (this.InvokeRequired)
            {
                dg_CloseForm method = CloseForm;
                this.Invoke(method);
            }
            else
            {
                this.Close();
            }
        }
    }
}
